package StockInfoSet;
use MarketInfo;
use StockInfo;
use ChannelInfo;
use Data::Dumper;
use threads::shared;

sub new{
	my %self:shared = ();
	$self{MARKET_INFO} = MarketInfo::new("ObjectInfo");
	$self{STOCK_INFOS} = &share([]);
	$self{CHANNEL_INFO} = ChannelInfo::new("ObjectInfo"); 
	bless \%self;
	return \%self; 	
}

sub market_info {
	my $self = shift;
	if (@_) {$self->{MARKET_INFO} = shift};
	return $self->{MARKET_INFO};			
}

sub stock_infos {
	my $self = shift;
	if (@_) {$self->{STOCK_INFOS} = shift};
	return $self->{STOCK_INFOS};			
}

sub from_channel {
	my $self = shift;
	if (@_) {$self->{CHANNEL_INFO}->set('NAME', shift);};
	return $self->{CHANNEL_INFO}->get('NAME');			
}

sub processing_time {
	my $self = shift;
	if (@_) {$self->{CHANNEL_INFO}->set('PROCESSING_TIME', shift);};
	return $self->{CHANNEL_INFO}->get('PROCESSING_TIME');			
}

sub start_time {
	my $self = shift;
	if (@_) {$self->{CHANNEL_INFO}->set('START_TIME', shift);};
	return $self->{CHANNEL_INFO}->get('START_TIME');			
}

sub sys_sequence {
	my $self = shift;
	if (@_) {$self->{CHANNEL_INFO}->set('SYS_SEQ', shift);};
	return $self->{CHANNEL_INFO}->get('SYS_SEQ');
}

sub status{
	my $self = shift;
	if (@_) {$self->{CHANNEL_INFO}->set('STATUS', shift);};
	return $self->{CHANNEL_INFO}->get('STATUS');	
}

sub message{
	my $self = shift;
	if (@_) {$self->{CHANNEL_INFO}->set('MESSAGE', shift);};
	return $self->{CHANNEL_INFO}->get('MESSAGE');
}

sub market_time{
	my $self = shift;
	if(!$self->{MARKET_INFO}){return 'undefined';}
	if (@_){$self->{MARKET_INFO}->set('Time', shift);};
	return $self->{MARKET_INFO}->get('Time');
}

sub push_stock_info{
	my $self = shift;
	my $stock_info = shift;
	push @{$self->{STOCK_INFOS}},$stock_info;	
}

sub delete{
	my $self = shift;
	$self->{MARKET_INFO} = undef if defined $self->{MARKET_INFO};
	$self->{CHANNEL_INFO} = undef if defined $self->{MARKET_INFO};
	if(defined $self->{STOCK_INFOS}){
		foreach my $stock_info (@{$self->{STOCK_INFOS}}){
			$stock_info = undef;
		}
		$self->{STOCK_INFOS} = undef;
	}	
}

sub DESTROY{
#	my $self = shift;	
#	print 'Info set destroy ' . $self->from_channel() . '|' . $self->sys_sequence();	
}
1;
